package com.niit.service.impl;

import java.util.List;

import com.niit.bean.Contacts;
import com.niit.dao.ContactsDao;
import com.niit.dao.impl.ContactsDaoImpl;
import com.niit.service.ContactsService;
import com.niit.utils.Page;

public class ContactsServiceImpl implements ContactsService {
	
	private ContactsDao dao = new ContactsDaoImpl();
	@Override
	public int add(Contacts t) {
		return dao.add(t);
	}

	@Override
	public int delete(Contacts t) {
		return dao.delete(t);
	}

	@Override
	public int update(Contacts t) {
		return dao.update(t);
	}

	@Override
	public Page<Contacts> getPage(String pagenum, String url) {
		int total = dao.findTotal();//查出总记录数
		Page<Contacts> page = null;
		if(pagenum == null){
			page = new Page<Contacts>(total,1);
		}else{
			page = new Page<Contacts>(total, Integer.parseInt(pagenum));
		}
		List<Contacts> list = dao.findAll(page.getStartIndex(), page.getEndIndex());
		page.setList(list);
		page.setUrl(url);
		return page;
	}

}
